package com.hxk;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 用户消息队列
 * @author Cactus
 */
@Component
public class UserPublisher {

	//注入交换器名称
	@Value("${mq.config.exchange}")
	private String exchange;
	//注入rabbitmq操作类
	@Autowired
	private AmqpTemplate amqpTemplate;
	/**
	 * 发送消息
	 * @param msg
	 */
	public void send(String msg) {
		/**
		 * 向消息队列发送消息
		 * 参数一：交换器名称
		 * 参数二：路由键
		 * 参数三：消息
		 */
		this.amqpTemplate.convertAndSend(this.exchange, "user.log.debug", "user.log.debug..."+msg);
		this.amqpTemplate.convertAndSend(this.exchange, "user.log.info", "user.log.info..."+msg);
		this.amqpTemplate.convertAndSend(this.exchange, "user.log.warn", "user.log.warn..."+msg);
		this.amqpTemplate.convertAndSend(this.exchange, "user.log.error", "user.log.error..."+msg);
	}
}
